﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace Sino.CapacityCloud.Web
{
    public enum CertificationStatus
    {
        None = 0,
        Uncommitted = 1,
        Pending = 2,
        Passed = 3,
        Rejected = 4
    }
    public class UsersResponse
    {
        public string Error { get; set; }
        public UsersResponses Response { get; set; }
    }
    public class UsersResponses
    {
        public string ExtData { get; set; }
        public int Total { get; set; }
        public IEnumerable<User> List { get; set; }
    }

    public class User
    {
        public string UserId { get; set; }
        public int RealNameState { get; set; }
        public string RealName { get; set; }
        public string PhoneNumber { get; set; }
        public bool IsLockedout { get; set; }
        public DateTime CertificationTime { get; set; }
        public string CarLength { get; set; }
        public string UserName { get; set; }
        public string CarType { get; set; }
        public string[] Roles { get; set; }
        public string CarNumber { get; set; }

    }
    public class UsersDetailResponse
    {
        public string Error { get; set; }
        public UserDetailResponse Response { get; set; }
    }
    public class UserDetailResponse
    {
        public string CarCode { get; set; }
        public string DrivingLicenseImage { get; set; }
        public int DrivingLicenseState { get; set; }
        public string IDCardImage { get; set; }
        public int IDCardState { get; set; }
        public string Message { get; set; }
        public string RealHeadImage { get; set; }
        public int RealHeadState { get; set; }
        public int State { get; set; }
        public string VehicleLicenseImage { get; set; }
        public int VehicleLicenseState { get; set; }
    }
    
    public class TagsResponse
    {
        public string Error { get; set; }
        public TagResponse Response { get; set; }
    }
    public class TagResponse
    {

    }
    public class putUserStatus
    {
        public string CarCode { get; set; }
        public int DrivingLicenseKeyStatus { get; set; }
        public int IdCardKeyStatus { get; set; }
        public int RealHeadKeyStatus { get; set; }
        public string UserId { get; set; }
        public int vehicleLicensekeyStatus { get; set; }
    }
    public class UsersEditResponse
    {
        public string Error { get; set; }
        public UserEditResponse Response { get; set; }
    }
    public class UserEditResponse
    {

    }
    public class UsersController : Controller
    {
        //获取用户列表
        [HttpGet("users")]
        public IActionResult users(string keyword, string carCode, DateTime? startTime, DateTime? endTime, string roleId, CertificationStatus state, bool useCache = true, int startIndex = 0, int count = 10)
        {
            var random = new Random();
            var list = new List<User>();
            for (var i = 0; i < 10; i++)
            {
                list.Add(new User()
                {
                    UserId = Guid.NewGuid().ToString(),
                    RealNameState = random.Next(0, 6),
                    RealName = "田平",
                    PhoneNumber = "13913871700",
                    IsLockedout = false,
                    CertificationTime = DateTime.Now,
                    CarLength = "250m",
                    UserName = "13913871700",
                    CarType = "箱车",
                    CarNumber = "苏F6666",
                    Roles = new string[] { "e7fdeff6-30c7-4fb6-af7b-ea4e5a6dc9bf" }
                });
            }
            var response = new UsersResponse()
            {
                Error = null,
                Response = new UsersResponses()
                {
                    ExtData = null,
                    Total = 20,
                    List = list
                }
            };

            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }
        //获取用户详情
        [HttpGet("users/{user_id}")]
        public IActionResult getDetail(string user_id)
        {
            if (user_id == null)
            {
                return BadRequest();
            }

            var response = new UsersDetailResponse()
            {
                Error = null,
                Response = new UserDetailResponse()
                {
                    CarCode = null,
                    DrivingLicenseImage = null,
                    DrivingLicenseState = 1,
                    IDCardImage = null,
                    IDCardState = 1,
                    Message = null,
                    RealHeadImage = null,
                    RealHeadState = 1,
                    State = 0,
                    VehicleLicenseImage = null,
                    VehicleLicenseState = 0
                }
            };
            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }

        //启用禁用
        [HttpGet("users/{user_id}/enabled")]
        public IActionResult SetAccountLockoutState(string user_id, bool disabled)
        {
            if (user_id == null)
            {
                return BadRequest();
            }
            var response = new TagsResponse()
            {
                Error = null,
                Response = new TagResponse() { }
            };

            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }
        //编辑用户实名认证状态
        [HttpPut("users/{user_id}")]
        public IActionResult putUserRealNameCertificationStatus(string user_id, [FromBody] putUserStatus putUserStatus)
        {
            if (user_id == null)
            {
                return BadRequest();
            }
            var response = new UsersEditResponse()
            {
                Error = null,
                Response = new UserEditResponse()
                {
                }
            };
            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }
    }
}
